package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.model.vo.UserInfoVoAge;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 通用设置管理控制层
 */
@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     *  用户通用设置 - 读取
     */
    @RequestMapping(value = "/settings",method = RequestMethod.GET)
    public ResponseEntity findSettings(){
        SettingsVo settingsVo = settingsService.findSettings();
        return ResponseEntity.ok(settingsVo);
    }


    /**
     *  设置陌生人问题 - 保存
     */
    @RequestMapping(value = "/questions",method = RequestMethod.POST)
    public ResponseEntity addQuestions(@RequestBody Map<String,String> params){
        String content = params.get("content");//陌生人问题
        settingsService.addQuestions(content);
        return ResponseEntity.ok(null);
    }


    /**
     *  通知设置 - 保存
     */
    @RequestMapping(value = "/notifications/setting",method = RequestMethod.POST)
    public ResponseEntity addSettings(@RequestBody Map params){
        boolean likeNotification = (boolean)params.get("likeNotification");//推送喜欢通知
        boolean pinglunNotification = (boolean)params.get("pinglunNotification");//推送评论通知
        boolean gonggaoNotification = (boolean)params.get("gonggaoNotification");//推送公告通知
        settingsService.addSettings(likeNotification,pinglunNotification,gonggaoNotification);
        return ResponseEntity.ok(null);
    }


    /**
     *  黑名单 - 翻页列表
     *  page: 默认值为第一页
     *  pagesize:默认值每页10条记录
     */
    @RequestMapping(value = "/blacklist",method = RequestMethod.GET)
    public ResponseEntity findPageBlackList(@RequestParam(value = "page",defaultValue = "1") Long page,@RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        PageResult<UserInfoVoAge>  pageResult = settingsService.findPageBlackList(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }



    /**
     * 移除黑名单
     * {blackUserId}:地址栏参数  @PathVariable Long blackUserId接收参数
     * @param blackUserId 被取消黑名单用户id
     * @return
     */
    @RequestMapping(value = "/blacklist/{blackUserId}",method = RequestMethod.DELETE)
    public ResponseEntity deleteBlackList(@PathVariable Long blackUserId){
        settingsService.deleteBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }
}
